﻿#include <QCoreApplication>
#include "CModelMng.h"
#include "CSqlOper.h"
#include "QXmlOper.h"
#include "CGlobal.h"

CModelMng::CModelMng()
{
	initCfg();//初始化xml文件
	m_bDbInit = CSqlOper::instance().initSql();

	// VLC性能优化参数
	const char* vlc_args[] = {
		"--no-xlib",
		"--avcodec-threads=4",
		"--network-caching=300",
		"--clock-synchro=0",
		"--drop-late-frames",
		"--skip-frames",
		"--no-snapshot-preview",
		"--avcodec-hw=dxva2"//启用硬件解码
	};

	// 初始化 VLC 实例
	m_pVlcInstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
	if (!m_pVlcInstance) {
		qFatal("Failed to create VLC instance.");
	}
	m_pExportResultTh = nullptr;
	m_pExportResultTh = new CExportResultTh();
	m_pExportResultTh->ThreadStart();
}

CModelMng::~CModelMng()
{
	if (m_pVlcInstance)
	{
		libvlc_release(m_pVlcInstance);
	}
	if (m_pExportResultTh != nullptr)
	{
		delete m_pExportResultTh;
		m_pExportResultTh = nullptr;
	}
}

void CModelMng::initCfg()
{
	QString m_strSystemLogDir = QCoreApplication::applicationDirPath();
	QString filename = m_strSystemLogDir + "/DLL/CorrectCfg/CorrectCfg.xml";
	XmlOper::SetXmlName(filename);
	QVector<QString>verHttpUrl;      //http文件服务地址前缀
	QVector<QString>vecResultPath;//报表导出路径
	QVector<QString>vecCustomName;
	QVector<QString>vecResultTime;
	verHttpUrl = ReadXmlS("Correct,HTTPURL,url,url");
	vecResultPath = ReadXmlS("Correct,OUTPATH,path,path");
	vecCustomName = ReadXmlS("Correct,CUSTOM,name,name");
	vecResultTime = ReadXmlS("Correct,RESULTTIME,time,time");
	if (verHttpUrl.size() >= 1)
	{
		g_sHttpUrl = verHttpUrl[0];
	}
	if (vecCustomName.size() >= 1)
	{
		g_sCustomName = vecCustomName[0];
	}
	if (vecResultTime.size() >= 1)
	{
		g_nResultTime = vecResultTime[0].toInt();
	}
	if (vecResultPath.size() >= 1)
	{
		g_sResultPath = vecResultPath[0];
	}
}